from rest_framework import serializers
from orders.models import OrderInfo, OrderGoods


class SkuSerializer(serializers.Serializer):
    name = serializers.CharField()
    default_image = serializers.ImageField()


class OrderGoodsSerializer(serializers.ModelSerializer):
    # 明确的关系属性，会默认输出主键，自定义指定序列化器
    sku = SkuSerializer(read_only=True)

    class Meta:
        model = OrderGoods
        fields = '__all__'


class OrderSerialzier(serializers.ModelSerializer):
    # 隐藏的关系属性，在指定all时也不会输出，需要明确定义
    skus = OrderGoodsSerializer(many=True, read_only=True)

    class Meta:
        model = OrderInfo
        fields = '__all__'
